var findJudge = function (n, trust) {
    const arr = new Array(n + 1).fill(0)
    for (const [a, b] of trust) {
        arr[a]--
        arr[b]++
    }
    for (let i = 1; i < arr.length; i++) {   
        if (arr[i] === n - 1) return i

    }
        return -1
};

console.log(findJudge(4, [[1, 4], [2, 4], [3, 4]]));
